package com.sy.api;

/**
 * @className: SectionsController
 * @author: Mr.Liu
 * @date: 2025/10/29 14:37
 * @Version: 1.0
 * @description:
 */

import com.sy.ResultVO;
import com.sy.pojo.Sections;
import com.sy.service.SectionsService;
import com.sy.utils.MinIOUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import java.util.Map;

@RestController
@RequestMapping("/api/sections")
@Tag(name = "章节管理模块")
@Slf4j
public class SectionsController {
    @Resource
    private SectionsService sectionsService;
    @GetMapping("/del")
    @Operation(summary = "删除小节")
    public ResultVO<Object> delSections(@RequestParam Map<String,String> map) throws Exception {
        log.info("删除小节的map值是:{},{}",map.get("id"),map.get("videoUrl"));
        //数据库删除
        boolean flag = sectionsService.removeById(map.get("id"));
        //minio的删除
        MinIOUtils.removeFile(map.get("videoUrl"));
        return flag?ResultVO.success():ResultVO.error();
    }
    @GetMapping("/update")
    @Operation(summary = "修改小节收费状态")
    public ResultVO<Object> updateSections(@RequestParam Map<String,Object> map){
        log.info("修改小节的map值是:{},{}",map.get("id"),map.get("free"));
        boolean flag = sectionsService.updateSections(map);
        return flag?ResultVO.success():ResultVO.error();
    }
    @GetMapping("/{id}")
    @Operation(summary = "根据id获取小节信息")
    public ResultVO<Object> queryById(@PathVariable Integer id){
        log.info("小节的id是:{}",id);
        Sections sections = sectionsService.getById(id);
        return ResultVO.success(sections);
    }

}
